<script setup>
import BackLink from "@/components/BackLink/index.vue"
import {useRoute, useRouter} from "vue-router";
const router = useRouter()
const route = useRoute()
import {addNotice, getNotice, updateNotice} from "@/api/system/notice";
const {proxy} = getCurrentInstance();
const editForm = ref({})

const getNoticeDetails = () => {
  const noticeId = route.query.id

  getNotice(noticeId).then(response => {
    editForm.value = response.data;
  });
}

const handleBack = () => {
  router.go(-1)
}

function submitForm() {
  if(!editForm.value.noticeTitle){
    proxy.$modal.msgError("请输入通知标题");
    return false;
  }
  if(!editForm.value.noticeContent){
    proxy.$modal.msgError("请输入通知内容");
    return false;
  }
  updateNotice(editForm.value).then(response => {
    proxy.$modal.msgSuccess("修改成功");
    handleBack()
  });
}

onMounted(() => {
  getNoticeDetails()
})
</script>

<template>
  <div class="outBox">
    <el-card>
      <BackLink/>
      <div class="form-box">
        <div class="form-line">
          <div class="form-item">
            <div class="form-name">创建人</div>
            <div class="form-cont">
              <span>{{ editForm.createBy }}</span>
            </div>
          </div>
          <div class="form-item">
            <div class="form-name">联系电话</div>
            <div class="form-cont">
              <span>{{ editForm.phone }}</span>
            </div>
          </div>
          <div class="form-item">
            <div class="form-name">创建时间</div>
            <div class="form-cont">
              <span>{{ editForm.createTime }}</span>
            </div>
          </div>
        </div>
        <div class="form-line">
<!--          <div class="form-item">-->
<!--            <div class="form-name">通知附件</div>-->
<!--            <div class="form-cont">-->
<!--              <el-input v-model="editForm.d" />-->
<!--            </div>-->
<!--          </div>-->
          <div class="form-item">
            <div class="form-name">通知标题</div>
            <div class="form-cont">
              <el-input v-model="editForm.noticeTitle" />
            </div>
          </div>
<!--          <div class="form-item">-->
<!--            <div class="form-name">发布时间</div>-->
<!--            <div class="form-cont">-->
<!--              <el-input v-model="editForm.f" />-->
<!--            </div>-->
<!--          </div>-->
        </div>
        <div class="form-textArea">
          <div class="form-item">
            <div class="form-name">通知内容</div>
            <div class="form-cont">
              <editor v-model="editForm.noticeContent" :min-height="192"/>
<!--              <el-input v-model="editForm.g" type="textarea"  :autosize="{ minRows: 4, maxRows: 20 }"/>-->
            </div>
          </div>
        </div>
        <div class="center-btns">
          <el-button  @click="handleBack">返回</el-button>
          <el-button  type="primary" @click="submitForm">编辑保存</el-button>
        </div>
      </div>
    </el-card>

  </div>
</template>

<style scoped lang="scss">
.center-btns{
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
.form-cont{
  span{
    margin-left: 10px;
  }
}
.form-textArea{
  border: 1px solid #e5e5e5;
  :deep(.el-textarea){
    --el-input-border-color:#fff !important;
    --el-input-focus-border:#fff !important;
    --el-input-hover-border-color:#fff !important;
    --el-input-focus-border-color:#fff !important;

  }
}
.form-box{
  .form-name{
    background: #f1f7ff;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    font-weight: bold;
    border-right: 1px solid #e5e5e5;
  }
  .form-line{
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border: 1px solid #e5e5e5;
    margin-bottom: 20px;
    .form-item{
      display: flex;
      align-items: center;

      .form-cont{
        width: calc(100% - 100px);
        :deep(.el-input){
          --el-input-border-color:#fff !important;
          --el-input-focus-border:#fff !important;
          --el-input-focus-border-color:#fff !important;
        }
      }
    }
  }
}
</style>
